package com.example.androiduidemo2.views;

import android.annotation.SuppressLint;
import android.util.Log;
import android.view.View;
import android.widget.ListView;


import com.example.androiduidemo2.R;
import com.example.androiduidemo2.adapter.FriendsAdapter;
import com.example.androiduidemo2.base.BaseFragment;
import com.example.androiduidemo2.bean.Student;
import com.example.androiduidemo2.widget.EmptyView;
import com.example.androiduidemo2.widget.HeaderView;

import java.util.ArrayList;
import java.util.List;

public class FriendsFragment extends BaseFragment implements View.OnClickListener {

   private HeaderView mHeaderView;
   private ListView mLvFriends;
   private EmptyView mEmptyView;
   private List<Student> mFriendsList;
   private FriendsAdapter mFriendsAdapter;
   @Override
   protected int getLayoutId() {
      return R.layout.fragment_friends;
   }

   @SuppressLint("WrongViewCast")
   @Override
   protected void initView() {
      mHeaderView = mView.findViewById(R.id.header_view);
      mHeaderView.setTitle("我的同学");
      mLvFriends = mView.findViewById(R.id.lv_friends);
      mEmptyView = mView.findViewById(R.id.empty_view);
      mLvFriends.setEmptyView(mEmptyView);
      mFriendsList = new ArrayList<>();
      mFriendsAdapter = new FriendsAdapter(mFriendsList, mContext);
      mLvFriends.setAdapter(mFriendsAdapter);
   }

   @Override
   protected void initListener() {
      mHeaderView.setRightClickListener(this);
   }

   @Override
   public void onClick(View v) {
      int id = v.getId();
      if (id == R.id.button_right) {
         addFriends();
      }
   }

   private void addFriends() {
      Log.d(TAG, "addFriends");
      Student student = new Student();
      student.setAge(18);
      student.setName("jim");
      mFriendsList.add(student);
      mFriendsAdapter.notifyDataSetChanged();
   }
}
